package com.myx.servlet.admin.category;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.myx.pojo.Category;
import com.myx.service.category.CategoryService;
import com.myx.service.category.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GetCategoryListServlet",value = "/GetCategoryListServlet")
public class GetCategoryListServlet extends HttpServlet {
    CategoryService categoryService=new CategoryServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Category> categoryList = this.categoryService.getCategoryList();
        Object jsonObject = JSONArray.toJSON(categoryList);
        String categoryListJson = JSON.toJSONString(jsonObject);
        response.getWriter().print(categoryListJson);


    }
}
